<%@page import="fr.uniscol.dao.impl.EleveDaoImpl"%>
<%@page import="fr.uniscol.model.Scolarite"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="UTF-8"
%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<jsp:useBean id="eleve" type="fr.uniscol.model.Eleve" scope="request" />

<script type="text/javascript">
	
	function editScolarite(eleveId, scolariteId){
		$("div.modal-body").load("eleve.scolarite.edit", 
								{"eleveid":eleveId, "scolariteid" : scolariteId},   
			function(){
                $("#btnSupprimerScolarite").hide();
                $("#btnEnregistrerScolarite").show();
        
				$("#scolariteFormModal").modal("show");
			}
		);
	}
    
    function deleteScolarite(eleveId, scolariteId){
        $("div.modal-body").html("Supprimer cette scolarité ?");

        $("#btnSupprimerScolarite").click(function(){
            location='eleve.scolarite.delete?eleveid=' + eleveId + '&scolariteid=' + scolariteId;
        });
        
        $("#btnSupprimerScolarite").show();
        $("#btnEnregistrerScolarite").hide();
        
        $("#scolariteFormModal").modal("show");
    }
</script>

<%  if(eleve.getScolarites().isEmpty()){ %>
    <div class="alert alert-warning"><span class="glyphicon glyphicon-warning-sign"></span>&nbsp;L'élève n'a aucune scolarité enregistrée !</div>
<%  } %>

<table class="table">
    <thead>
        <th>Scolarité actuelle</th>
        <th>MEF</th>
        <th>Classe</th>
        <th>Options</th>
        <th>Période</th>
        <th></th>
    </thead>
    <tbody>
<%
	for(Scolarite sco : eleve.getScolarites()){
%>	
    <c:set var="sco" value="<%=sco %>" />
    <tr>
        <td><% if(sco.isActuelle()){ %><span class="glyphicon glyphicon-ok"/><% } %></td>
        <td><%=sco.getMef().getLibelleLong() %></td>
        <td><a href="<c:url value="classe.edit?classeid=" /><%=sco.getClasse().getId() %>"><%=sco.getClasse().getLibelle() %></a></td>
        <td>
            <ul>
            <c:forEach var="opt" items="${sco.options}">
                <li>${opt.matiere.libelleLong} (${opt.modalite})</li>
            </c:forEach>
            </ul>
        </td>
        <td><%=sco.getPeriode() %></td>
        <td>
            <button type="button" class="btn btn-primary btn-xs" onClick="javascript:editScolarite(${eleve.id}, ${sco.id})" />Modifier</button>
            <button type="button" class="btn btn-primary btn-xs" onClick="javascript:deleteScolarite(${eleve.id}, ${sco.id})">Supprimer</button>
        </td>
    </tr>
<%	} %>
	<tr>
        <td colspan="5">
            <button type="button" class="btn btn-primary btn-xs" onClick="javascript:editScolarite(${eleve.id}, 0)">Ajouter une scolarité</button>     
        </td>
	</tr>
    </tbody>
</table>

<!-- MODAL -->
<div id="scolariteFormModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Scolarité</h4>
      </div>
      <div class="modal-body">
		
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
        <button id="btnSupprimerScolarite" type="button" class="btn btn-primary">Supprimer la scolarité</button>
        <button id="btnEnregistrerScolarite" type="submit" class="btn btn-primary" form="frmScolarite">Enregistrer</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
